package com.shcowin.dao.impl;

import java.util.List;

import javax.inject.Inject;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.shcowin.dao.ProductsDao;
import com.shcowin.entity.News;
import com.shcowin.entity.Products;
import com.shcowin.mapper.ProductsMapper;


@SuppressWarnings("unchecked")
@Repository
public class ProductsDaoImpl implements ProductsDao {

	@Inject
	private ProductsMapper mapper;

	public boolean add(Products entity) throws DataAccessException {
		boolean flag = false;
		try {
			mapper.add(entity);
			flag = true;
		} catch (DataAccessException e) {
			flag = false;
			throw e;
		}
		return flag;
	}
	
	public boolean edit(Products entity) throws DataAccessException {
		boolean flag = false;
		try {
			mapper.edit(entity);
			flag = true;
		} catch (DataAccessException e) {
			flag = false;
			throw e;
		}
		return flag;
	}

	public Products getById(Integer id) throws DataAccessException {
		Products entity = null;
		try {
			entity = mapper.getById(id);
		} catch (DataAccessException e) {
			throw e;
		}
		return entity;
	}
	
	public Products getByName(String name) throws DataAccessException {
		Products entity = null;
		try {
			entity = mapper.getByName(name);
		} catch (DataAccessException e) {
			throw e;
		}
		return entity;
	}

	public List<Products> getAll() throws DataAccessException {
		return mapper.getAll();
	}

	public void del(int id) throws DataAccessException {
		mapper.del(id);
		
	}

	public List<Products> getByPage(int start, int size) throws DataAccessException {
		 
		return mapper.getByPage(start, size);
	}

	public int getCount() throws DataAccessException {
		return mapper.getCount();
	}

	public List<Products> getByHomeMark() {
		return mapper.getByHomeMark();
	}

	public int getHomeMarkCount() {
		return mapper.getHomeMarkCount();
	}
}